package com.ideal.manage.esms.controller.report;


import com.ideal.manage.esms.bean.DTO.PageDto;
import com.ideal.manage.esms.bean.report.Report;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("report")
public class ReportController {

    /**
     * 报表列表请求
     * @param model
     */
    @RequestMapping("report_list")
    public void reportList(Model model){

    }

    /**
     * 报表列表数据
     * @return
     */
    @RequestMapping("report_data")
    @ResponseBody
    public PageDto reportData(){

        List<Report> reports = new ArrayList<>();

        Report report1 = new Report();
        report1.setName("2018-01月报");
        report1.setCreateTime(new Date());
        report1.setReportCategory("1");
        reports.add(report1);

        Report report2 = new Report();
        report2.setName("2018-02月报");
        report2.setCreateTime(new Date());
        report2.setReportCategory("1");
        reports.add(report2);

        Report report3 = new Report();
        report3.setName("2018年年报");
        report3.setCreateTime(new Date());
        report3.setReportCategory("2");
        reports.add(report3);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(2L);
        pageDto.setRows(reports);

        return pageDto;
    }

    /**
     *  报表详情
     * @param id
     */
    @RequestMapping("report_detail")
    public void reportDetail(Model model,
                             @RequestParam(value = "id", required = false) Long id) {

        Report report = new Report();
        report.setName("2018-01月报");
        report.setCreateTime(new Date());
        report.setReportCategory("1");
        StringBuffer content = new StringBuffer()
                .append("1.     电池储能系统该月的充电电量(kWh),平均效率\r\n")
                .append("2.     故障信息统计\r\n")
                .append("3.     月收益表\r\n")
                .append("4.     月储能系统安全运行周期\r\n")
                .append("5.     诊断信息\r\n")
                .append("6.     诊断信息的图片信息展示(最新一次的结果展示)\r\n")
                .append("7.     储能系统电池状态评价");
        report.setContent(content.toString());

        model.addAttribute("report", report);
    }
}
